package com.frx.leetoffer.dayone;

/**
 * Created with IDEA
 * @description 旋转数组中的最小数字
 * @author: xrf
 * @Date: 2019/11/17
 * @Time: 17:46
 */
public class MinRotateArray {

    public static void main(String[] args){
        int[] arr = {3,4,5,1,2};
        System.out.println(solution(arr));
    }
    public static int solution(int[] array){
        if (array.length == 0){
            return 0;
        }
        int left = 0;
        int right = array.length-1;
        while (left<= right){
            int mid = (left + right) /2;
            if (array[mid] < array[mid-1]){
                return array[mid];
            } else if (array[mid] > array[right]){
                left = mid+1;
            } else {
                right = mid -1;
            }
        }
        return 0;
    }
}
